<template>
  <div class="container" />
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { useStore } from 'vuex'
import { useRouter, useRoute } from 'vue-router'
import { Toast } from 'vant'
import { getUrl } from '@/utils/auth'
export default defineComponent({
  setup() {
    const router = useRouter() // 组件内路由
    const route = useRoute() // 组件内路由信息
    const store = useStore()
    let promiseb
    const promisea = store.dispatch('user/login', { code: route.query.code }).then(() => {
      promiseb = store.dispatch('user/getUserInfo').then((res) => {
        if (!res.mobile) {
          router.replace({ name: 'BindPhone' })
          return
        }
        const beforeLoginUrl = getUrl()
        if (beforeLoginUrl) {
          window.location.replace('/#' + beforeLoginUrl)
        } else {
          router.replace({ name: 'ConfirmWork' })
        }
      })
    })
    Promise.all([promisea, promiseb]).then(() => {
      Toast.clear()
    })
  }
})
</script>

<style lang="less" scoped>
.container {
  position: absolute;
  height: 100%;
  width: 100%;
  background-color: #ffffff;
  .top {
    width: 100%;
    height: 331px;
  }
  .bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
  }
}
</style>

